package com.ruoyi.system.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.system.domain.PCabinet;
import com.ruoyi.system.domain.PProduct;
import com.ruoyi.system.mapper.PProductMapper;
import com.ruoyi.system.service.IPCabinetService;
import com.ruoyi.system.service.IPProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * 商品管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@Service
public class PProductServiceImpl extends ServiceImpl<PProductMapper, PProduct> implements IPProductService
{

    @Autowired
    private IPCabinetService cabinetService;

    /**
     * 查询商品管理
     * 
     * @param id 商品管理主键
     * @return 商品管理
     */
    @Override
    public PProduct selectPProductById(Long id)
    {
        return baseMapper.selectPProductById(id);
    }

    /**
     * 查询商品管理列表
     * 
     * @param pProduct 商品管理
     * @return 商品管理
     */
    @Override
    public List<PProduct> selectPProductList(PProduct pProduct)
    {
        return  baseMapper.selectPProductList(pProduct);
    }

    /**
     * 新增商品管理
     * 
     * @param pProduct 商品管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPProduct(PProduct pProduct)
    {
        if(pProduct.getCabinetId()!=null){
            PCabinet pCabinet = cabinetService.selectPCabinetById(pProduct.getCabinetId());
            pProduct.setCabinetCode(pCabinet.getCode());
            pProduct.setWarehouseId(pCabinet.getWareHouseId());
            pProduct.setWarehouseName(pCabinet.getWarehouseName());
            pProduct.setLayer(pCabinet.getLayer());
            //pProduct.setBoxNo(pCabinet.getBoxNo());
        }
        return baseMapper.insert(pProduct);
    }

    /**
     * 修改商品管理
     * 
     * @param pProduct 商品管理
     * @return 结果
     */
    @Override
    public int updatePProduct(PProduct pProduct)
    {
        if(pProduct.getCabinetId()!=null){
            PCabinet pCabinet = cabinetService.selectPCabinetById(pProduct.getCabinetId());
            pProduct.setCabinetCode(pCabinet.getCode());
            pProduct.setWarehouseId(pCabinet.getWareHouseId());
            pProduct.setWarehouseName(pCabinet.getWarehouseName());
            pProduct.setLayer(pCabinet.getLayer());
            //pProduct.setBoxNo(pCabinet.getBoxNo());
        }

        return  baseMapper.updateById(pProduct);
    }

    /**
     * 批量删除商品管理
     * 
     * @param ids 需要删除的商品管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deletePProductByIds(Long[] ids)
    {
        return baseMapper.deletePProductByIds(ids);
    }

    /**
     * 删除商品管理信息
     * 
     * @param id 商品管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deletePProductById(Long id)
    {
        return baseMapper.deletePProductById(id);
    }

    @Override
    public PProduct getInfoByCabinetId(Long cabinetId,Long boxNo) {
        return baseMapper.getInfoByCabinetId(cabinetId,boxNo);
    }


}
